<template>
    <div id='commonConfig'>
        <div class="main1">
            <span>自动审核</span>
        </div>
        <div class="main2">
            <el-switch
                @change="switchChange"
                v-model="value3"
                inactive-text="开启自动"
                active-text="关闭自动">
            </el-switch>
        </div>
        <div class="main1">
            <span>通知信息</span>
            <el-button type="primary" @click="show_new_notice=true">新增通知</el-button>
        </div>
            <div class="main444">
                <div style="min-height:240px;" >
                <loading v-show="isShow"></loading>
                    <el-table
                    v-show="!isShow"
                    :data="tableData"
                    stripe
                    style="width: 100%;">
                    <el-table-column
                    prop="pushTime"
                    align="center"
                    label="推送日期">
                    </el-table-column>
                    <el-table-column
                    prop="title"
                    align="center"
                    label="标题">
                    </el-table-column>
                    <el-table-column
                    prop="content"
                    align="center"
                    label="通知内容">
                    </el-table-column>
                </el-table>
                </div>
                <div class="main2-b">
                    <el-pagination
                    v-show="tableData.length"
                    class="mrtopmrtop"
                    @current-change="handleCurrentChange"
                    :page-size="pageSize"
                    :current-page="currentPage1"
                    :pager-count="5"
                    layout="total, prev, pager, next, jumper"
                    :total="total"
                    :background="true">
                </el-pagination>
                </div>
            </div>
        <div class="main1 mrt20">
            <span>当日放款额限制</span>
        </div>
        <div class="main2">
            <span class="fl">每日放款额限制</span>
            <el-input
              class="fl wid"
              placeholder="请输入内容"
              v-model="input1"
              clearable>
            </el-input>
            
            <span style="margin-left:20px;" class="fl">元</span>
            <el-button type="primary" style="margin-left:20px;"  @click="saveFn">保存</el-button>
        </div>
        <!-- <div class="main3">
            <el-button type="primary"  @click="saveFn">保存</el-button>
        </div> -->


        <!--新增通知  -->
        <modal  
            :show='show_new_notice' 
            title='新增通知'
            :loading='loading_reject'
            @confirm='confirmHandle'
            @close='show_new_notice=false'>
            <div class="item">
                <span class="mar">标题:</span>
                <el-input v-model="input" placeholder="请输入内容" clearable></el-input>
            </div>
            <div class="item mrtop">
                <span>通知内容:</span>
                 <textarea class='modal__textarea1' rows="5" placeholder="请输入通知内容" v-model='rejectReason'></textarea>
            </div>
           
        </modal>
    </div>
</template>

<script>
    import modal from '../components/Modal.vue'
    import  { mapGetters, mapActions }  from 'vuex'
    import { commonConfigFn } from '../validation/validation'
    import loading from '../components/Loading.vue'
    import { systemApi } from '../api/api'
    export default {
        components:{
            modal,
            loading
        },
        data() {
            return {
                value3:true,
                show_new_notice:false,
                loading_reject:false,
                rejectReason:"",
                input:"",
                tableData: [],
                pageIndex:1,
                currentPage1:1,
                total:null,
                input1:'',
                isLoading:true,
                show_money:false,
                loading_reject:false,
                isSave:false,
                acSwitch:'2',
                message:"关闭自动审核",
                pageIndex:1,
                pageSize:4,
                isShow:false,
            }
        },
        computed:{
           
        },
        methods:{
            ...mapActions([
                'showLoading',
                'hideLoading',
                'setMsgTip'
            ]),
            switchChange(item){
                console.log(item)
                if(item){
                    this.acSwitch='2'
                    this.message="关闭自动审核"
                }else{
                    this.acSwitch='1'
                    this.message="开启自动审核"
                }
                this.isStartFn()
            },
            handleChange(value) {
               /* console.log(this.input1);
                if(this.input1<=0){
                    this.$refs.input11.focus()
                    this.setMsgTip({
                        text:'请您重新输入数额',
                        type:'warn'
                    })
                    this.isSave=false
                }else{
                    this.isSave=true
                }*/
            },
            /*blurFn(){
                console.log(this.input1)
                if(this.input1<=0){
                    this.$refs.input11.focus()
                    this.setMsgTip({
                        text:'请您重新输入数额',
                        type:'warn'
                    })
                    this.isSave=false
                    this.input1=0
                    console.log(888)
                }else if(this.input1==""||this.input1==undefined){
                    this.$refs.input11.focus()
                    this.setMsgTip({
                        text:'请您输入数额',
                        type:'warn'
                    })
                    this.isSave=false
                    this.input1=0
                }else{
                    this.isSave=true
                }
            },*/
            //初始化自动审核
            startInitFn(){
                systemApi.systemGetAutoCheckSwitch()
                .then(result=>{
                    console.log(result)
                    if(result==2){
                        this.value3=true
                    }else{
                        this.value3=false
                    }
                })
                .catch(error => {
                    console.error(error)
                })
            },
            //改变审核状态，调用审核接口
            isStartFn(){
                let msg={
                    acSwitch:this.acSwitch,
                }
                systemApi.systemGetAutoCheckSwitch(msg)
                .then(result=>{
                    this.$notify({
                      title: '提示',
                      message: this.message,
                      duration: 1500,
                    });
                })
                .catch(error => {
                    console.error(error)
                })
            },
            confirmHandle(){
                this.addSystemList()
            },
            //通知列表初始化
            systemList(){
                let msg={
                    pageIndex:this.pageIndex,
                    pageSize:this.pageSize,
                }
                this.isShow=true
                systemApi.systemNoticeInfoList(msg)
                .then(result=>{
                    console.log(result)
                    this.isShow=false
                    this.tableData=result.page.list
                    this.total=result.page.totalRow
                    this.currentPage1=result.page.pageNumber
                })
                .catch(error => {
                    this.isShow=false
                    console.error(error)
                })
            },
            //新增通知信息
            addSystemList(){
                let msg={
                    content:this.rejectReason,
                    title:this.input
                }
                if(!commonConfigFn(msg)) return 
                this.isShow=true
                systemApi.systemAddNoticeInfo(msg)
                .then(result=>{
                    console.log(result)
                    this.isShow=false
                    this.show_new_notice=false
                    this.pageIndex=1
                    this.systemList()
                })
                .catch(error => {
                    this.isShow=false
                    console.error(error)
                })
            },
            confirmHandleMoney(){
                 return true
                 
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.pageIndex=val;
                this.systemList()
            },
            addAjax(){
               /* let msg={
                    lendAmountMax:this.input1
                }*/
                systemApi.systemSetLendAmountLimit()
                .then(result=>{
                    console.log(result)
                    this.input1=result
                })
                .catch(error => {
                    this.isShow=false
                    console.error(error)
                })
            },
           
            //保存函数
            saveFn(){
                this.$confirm('此操作将保存放款额度限制, 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'success',
                  beforeClose:(action, instance, done)=>{
                        console.log(action)
                        if (action === 'confirm') {
                            instance.confirmButtonLoading = true;
                            instance.confirmButtonText = '保存中...';
                            /*if(!this.confirmHandleMoney()){
                                return false
                            }
                            instance.confirmButtonLoading = false*/
                            let msg={
                                lendAmountMax:this.input1
                            }
                            systemApi.systemSetLendAmountLimit(msg)
                            .then(result=>{
                                console.log(result)
                                this.input1=result
                                instance.confirmButtonLoading = false
                            })
                            .catch(error => {
                                this.isShow=false
                                instance.confirmButtonLoading = false
                                console.error(error)
                            })
                            done()
                        }
                        if(action === 'cancel'){
                            done()
                        }
                  }
                }).then(() => {

                }).catch(() => {

                });
            }
        },
        created(){
           // this.isStartFn()
            this.systemList()
            this.addAjax()
            this.startInitFn()
        },
    }
</script>
<style>
    .el-message-box__message p{
        font-weight: normal!important;
    }
    .el-message-box__title span{
        font-weight: normal!important;
    }
    .el-message-box__btns .el-button{
        height: 40px;
        line-height: 40px
    }
</style>
<style lang="scss" scoped>
    #commonConfig{
        padding:20px;
        font-weight: normal;
        .el-button{
            padding:0;
            width: 96px;
            height: 40px;
            line-height: 18px;
            text-align: center;
            font-size: 16px;
        }
        .el-switch__label *{
            font-weight: 15px;
        }
        .loading{
            margin-top:0;
            position: absolute;
            z-index:2;
            top:40%;
        }
        
    }
    .main444{
        height:300px;
        position: relative;
    }
   .main1{
        height:40px;
        font-size: 16px;
        line-height: 40px;
        text-indent: 20px;
        border-left:4px solid #3399ff;
        margin-bottom:20px;
        span {
            float: left;
            margin-right:40px;
        }
   }
   .main2{
    height:40px;
    line-height: 40px;
    margin-top: 10px;
    margin-bottom:20px;
    padding-left: 20px;
   }
   
   .item{
    width:90%;
    margin:0 auto;
    span{
        float: left;
        height:40px;
        line-height: 40px;
        margin-right:20px;
    }
    .el-input{
        width:300px;
    }
   }
   .modal__textarea1{
        border:1px solid #dcdfe6;
        padding: 10px;
        box-sizing: border-box;
        border-radius: 4px;
        font-size: 14px;
        width:300px;
   }
   .mrtop{
        margin-top:20px;
   }
    .fl{
        float: left;
        font-size: 15px;
    }
    .wid{
        width:200px;
        margin-left:20px;
    }
    .main3{
        margin:30px auto 0;
        text-align: center;
    }
    
    .mrt20{
        margin-top: 20px;
    }
    .main2-b{
        height:30px;
        margin-top:10px;
    }
    .item .mar{
        margin-right:51px;
    }
</style>
